const Joi = require("joi");
module.exports = class MantraController extends colpu.Controller {
  /**
   * @api {get} /api/mantra 获得咒语
   * @apiDescription 获得用户咒语
   * @apiGroup  咒语接口
   * @apiVersion 1.0.0
   *
   * @apiHeader {String} Authorization 用户token
   * @apiHeaderExample {json} Header-Example:
   * {
   *  "Authorization": "Bear ud9lC7iiYUC9LWytfd0KY8Qf7ixu4SFl96TJhlpdBFSrFBBNnqEQaha5BtdOGvHSpIVGoDJmklxXDVjSOgCPH8tkDCtS4+C/3s6uNpJpnb8="
   * }
   *
   * @apiSuccess {Number} status 状态码
   * @apiSuccess {String} message 消息
   * @apiSuccess {Object} data 返回结果
   * @apiSuccessExample {json} Success-Response:
   * HTTP/1.1 200 OK
      {
        "data": {
          ...
        },
        "status": 0,
        "message": "ok"
      }
  */
  async getMantra(ctx) {
    await ctx.validateAsync({
      query: {
        uid: Joi.string(),
      },
      status: 10001,
    });
    const res = await this.service.mantra.getMantra(ctx.query);
    ctx.respond(res);
  }
  /**
   * @api {post} /api/mantra 提交咒语
   * @apiDescription 用户新增咒语
   * @apiGroup  咒语接口
   * @apiVersion 1.0.0
   *
   * @apiParam {String} name 咒语名称
   * @apiParam {String} content 咒语内容
   * @apiParam {Number} [isplus] 是否显示plus
   *
   * @apiSuccess {Number} status 状态码
   * @apiSuccess {String} message 消息
   * @apiSuccess {Object} data 返回结果
   * @apiSuccessExample {json} Success-Response:
   * HTTP/1.1 200 OK
      {
        "status": 0,
        "message": "ok"
      }
  */
  async postMantra(ctx) {
    await ctx.validateAsync({
      body: {
        type: Joi.string().required(),
        uid: Joi.string().required(),
        title: Joi.string(),
        content: Joi.string(),
        isplus: Joi.number(),
      },
      status: 10001,
    });
    const res = await this.service.mantra.postMantra(ctx.request.body);
    ctx.respond(res);
  }
  /**
   * @api {put} /api/mantra 修改咒语
   * @apiDescription 今日元气统计
   * @apiGroup  咒语接口
   * @apiVersion 1.0.0
   * @apiParam {Number} id 咒语id
   * @apiParam {String} [name] 咒语名称
   * @apiParam {String} [content] 咒语内容
   * @apiParam {Number} [isplus] 是否显示plus
   *
   * @apiSuccess {Number} status 状态码
   * @apiSuccess {String} message 消息
   * @apiSuccess {Object} data 返回结果
   * @apiSuccessExample {json} Success-Response:
   * HTTP/1.1 200 OK
      {
        "status": 0,
        "message": "ok"
      }
  */
  async putMantra(ctx) {
    await ctx.validateAsync({
      body: {
        id: Joi.number().required(),
        type: Joi.string().required(),
        title: Joi.string(),
        content: Joi.string(),
        isplus: Joi.number(),
      },
      status: 10001,
    });
    await this.service.mantra.putMantra(ctx.request.body);
    ctx.respond(null);
  }
};
